package com.woniuxy.Test;

import com.woniuxy.bean.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PersonFactory {
    public static Person makePerson(){
        //读取配置文件
        Properties properties = new Properties();
        //需要一个输入流
        InputStream inputStream = Test.class.getResourceAsStream("../util/person.properties");
        Person person = null;
        try {
            properties.load(inputStream);
            //properties这个对象中，有没有办法获取到文件流中的内容？通过key获取全限定类名
            String str = properties.getProperty("person");
            person = (Person) Class.forName(str).newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IOException e) {
            e.printStackTrace();
        }
        return person;
    }
}

